package edu.uow.devdocs

import grails.converters.*
import edu.uow.devdocs.Issue

class IssueController {

    static scaffold = true
	
	def currentUserService
	def statusService
	
	def ajaxGetIssues(Integer id, String update) {
		def list = Issue.findAllByProject(Project.get(id))
		def result = ['id':update, 'data':
		list.collect() {
			[
				id:it.id,
				description:it.description
			]
		}]
		render result as JSON
	}
	
	def list() {
		params.max = Math.min(params.max ? params.int('max') : 25, 100)
		render(view:'list',
			model:[issueInstanceList: Issue.list(params),
				issueInstanceTotal: Issue.count(),
				userProjects:currentUserService.currentUser.projects])
	}
	
	def resolve() {
		statusService.resolveCascadeIssue(Issue.get(params?.id))
		redirect(action:'edit' , 'id': params?.id) 
	}
	
}
